﻿@using Abp.Application.Services.Dto;
@using FwProject.Car
@using FwProject.Car.Dto
@using X.PagedList
@using FwProject.Authorization
@model IPagedList<CarInfoDto>
@{
    ViewBag.Title = "汽车管理";
}
@section styles{

    <link href="~/Theme/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="~/Theme/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="~/Theme/js/plugins/layer/skin/layer.css" rel="stylesheet" />
    <link href="~/Scripts/webuploader-0.1.5/webuploader.css" rel="stylesheet" />
    <link href="~/Scripts/fancybox-2.1.7/source/jquery.fancybox.css" rel="stylesheet" media="screen" />
    <link href="~/Theme/css/plugins/jsTree/style.min.css" rel="stylesheet" />
    <style type="text/css">
        .input-group[class*=col-] {
            padding: 0 15px;
        }
    </style>
}
<div class="row wrapper wrapper-content animated fadeInRight">
    <div class="col-sm-2 @(IsGranted(PermissionNames.Factory_All)?"":"hidden")">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>工厂</h5>
                <div class="ibox-tools"></div>
            </div>
            <div class="ibox-content" style="padding-left:0px">
                <div id="cd_tree">

                </div>
            </div>
        </div>
    </div>
    <div class="@(IsGranted(PermissionNames.Factory_All)?"col-sm-10":"col-sm-12")" style="padding-left:0;">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>@ViewBag.Title</h5>
                <div class="ibox-tools">
                    <a class="btn btn-primary btn-xs" href="/Car/ExportExcel">Excel导出</a>
                    <button class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modal_ajax" data-url="@Url.Action("Create")" data-backdrop="static"><i class="fa fa-plus"></i>添加车辆</button>
                </div>
            </div>
            <div class="ibox-content">
                <div class="row m-b-sm m-t-sm">
                    <form class="form-horizontal" id="form" asp-controller="Car" asp-action="Index" data-ajax="true" data-ajax-update="#data_list" data-ajax-method="Get" data-ajax-mode="replace">
                        <input type="hidden" id="size" name="size" value="0" />
                        <input type="hidden" name="factoryid" id="factoryid" value="" />
                        <div class="col-md-5">
                            <div class="input-group">
                                <input type="text" name="keyword" placeholder="请输入车牌号" class="input-sm form-control"> <span class="input-group-btn">
                                    <button type="submit" class="btn btn-sm btn-primary"> 搜索</button>
                                </span>
                            </div>
                        </div>
                    </form>
                </div>
                <div id="data_list">
                    @*@{Html.RenderPartial("IndexPartial", Model);}*@
                </div>
            </div>
        </div>
    </div>
</div>
<div id="modal_ajax" class="modal inmodal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
</div>
<div id="modal_del" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated fadeIn">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                <h4 class="modal-title">删除</h4>
            </div>
            <form action="" method="post" novalidate="novalidate" data-ajax="true" data-ajax-success="DeletAjaxCallback" data-ajax-failure="FailureAjaxCallback" data-ajax-method="Post" role="form">
                @Html.AntiForgeryToken()
                <div class="modal-body">
                    <p>确定要删除？</p>
                    @*<input type="hidden" name="id" value="" />*@
                </div>
                <div class="modal-footer">
                    <button type="reset" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button id="btn_del_sure" type="submit" class="btn btn-danger" data-loading-text="执行中...">确定</button>
                </div>
            </form>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
@section scripts{
    <script src="~/Theme/js/content.min.js?v=1.0.0"></script>
    <script src="~/Theme/js/plugins/iCheck/icheck.min.js"></script>
    <script src="~/Theme/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="~/Theme/js/content.min.js?v=1.0.0"></script>
    <script src="~/Theme/js/plugins/iCheck/icheck.min.js"></script>
    <script src="~/Theme/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="~/Scripts/webuploader-0.1.5/webuploader.min.js"></script>
    <script src="~/Theme/js/plugins/suggest/bootstrap-suggest2014.js"></script>
    <script src="~/Scripts/fancybox-2.1.7/source/jquery.fancybox.js"></script>
    <script src="~/Theme/js/plugins/jsTree/jstree.min.js"></script>
    <script src="~/Scripts/jquery.treegrid.min.js"></script>
    <script type="text/javascript">
        //layer.msg("test",{time:2000});

        var loadCount = 0;
        var id = 0;
        $.getJSON("/Factory/GetFactoryTree?isType=false").done(function (data) {
            CommonAjaxCallback(data, function () {
                if (data.result.length > 0) {
                    var node = data.result[0];
                    if (node.type == "GC") {
                        layer.msg('数据加载中！', {
                            icon: 6
                        });

                    }
                }
                $("#cd_tree").on('changed.jstree', function (e, data) {
                    loadCount++;
                    if (loadCount == 1) {
                        return false;
                    }
                    id = data.instance.get_node(data.selected[0]).id;
                    var fid = data.instance.get_node(data.selected[0]).original.factoryId;
                    $('#factoryid').val(fid);
                    layer.msg('页面加载中！', {
                        icon: 6
                    });
                    $("#data_list").load("/Car/Index?factoryid=" + fid + "&r=" + Math.random(), function () {
                        $
                        layer.closeAll();
                        if ($('#che').parent().hasClass("checked")) {
                            $(".td1").children().addClass("hidden");
                        }
                        $(".i-checks").iCheck({ checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green", });
                    });
                }).on('loaded.jstree', function () {
                    $("#cd_tree").jstree('select_node', '' + data.result[0].id + '');
                    $("#cd_tree").jstree('open_all', data.result[0]);
                })
                    .jstree({
                        'core': {
                            'data': data.result,
                            "multiple": false,
                        },
                        "types": {
                            "GC": {
                                "icon": "fa fa-folder"
                            },
                            //"department": {
                            //    "icon": "fa fa-leaf"
                            //}
                        },
                        "plugins": ["types"]
                    });
            }, null);
        }).fail(function () {
            layer.msg('连接超时，获取工厂信息失败！', {
                icon: 2,
                time: 4000
            });
        });



        $(document).ready(function () {
            $('#modal_ajax').on('show.bs.modal', function (e) {
                $(this).addClass('loading');
                var $button = $(e.relatedTarget);
                var url = $button.data('url');
                if (!!url) {
                    url = url + ((url.indexOf("?") > -1) ? "&r=" : "?r=") + Math.random();
                    $(this).load(url, function () {
                        $.validator.unobtrusive.parse(this); //$("#form_model_create").validate();
                        $("input[name='CarOld']").datepicker({ todayBtn: "linked", keyboardNavigation: !1, forceParse: !1, calendarWeeks: !0, autoclose: !0 });
                        $(".i-checks").iCheck({ checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green", });
                        $(this).removeClass('loading');
                    });
                }
            });
            $('#modal_ajax').on('hidden.bs.modal', function (e) {
                $(this).empty();
            });

            $('#modal_del,#modal_password_reset').on('show.bs.modal', function (e) {
                var $button = $(e.relatedTarget);
                var url = $button.data('url');
                if (!!url)
                    url = url + ((url.indexOf("?") > -1) ? "&r=" : "?r=") + Math.random();
                $(this).find("form").attr("action", url);
            });
            $('#modal_del,#modal_password_reset').on('hidden.bs.modal', function (e) {
                $(this).find("form").attr("action", "");
            });
        });
        function DeletAjaxCallback(data, successInfo) {
            CommonAjaxCallback(data, function () {
                $($button).parent().parent().remove();
                $("#modal_del").modal("hide");
            }, successInfo);
        }

        function ReloadAjaxCallbackgoback(data, successInfo) {
            CommonAjaxCallback(data, function () {
                $('#modal_ajax').modal("hide");
                window.location.reload();
            }, successInfo);
        }

        $("#data_list").on("change", "#pageSize", function () {
            var size = $("option:selected", this).val();
            $("#size").val(size);
            $("#form").submit();
        });
    </script>
}